Skip to content

Add optional Monaco code editor autoformat - #13

Open
cherepanov wants to merge 9 commits into
masterfrom
12-feature-add-optional-monaco-code-editor-autoformat
Open

cherepanov wants to merge 9 commits into
masterfrom
12-feature-add-optional-monaco-code-editor-autoformat

Conversation

@cherepanov

Copy link
Copy Markdown
Collaborator

Summary

Packages affected

  • @react-form-builder/designer
  • tests/component

Checklist

  • I followed CONTRIBUTION.md and CONTRIBUTING.md
  • I ran npm run check-all locally (or explain why not)
  • Tests updated/added under tests/ when appropriate
  • Docs updated under documentation/docs for user-facing changes
  • External contributors: I have signed the CLA (comment the sign phrase on this PR if CI asks)

Breaking changes / migration

None.

Manual testing

Use the demo/designer with a form that has JSON editors (Edit JSON and property JSON). Compare compact vs formatted buffers.

1. Edit JSON — paste minified form (shows the difference)

  1. Open Designer.
  2. Click Edit JSON.
  3. Select all and replace with the minified login form below.
  4. Confirm Monaco reformats it to the pretty shape (newlines + 2-space indent) via format-on-paste / format document.
  5. Save/close and confirm the canvas still shows Login + Password inputs (data-testid login / password).

Minified (paste this):

{"version":"1","form":{"key":"Screen","type":"Screen","props":{},"children":[{"key":"login","type":"RsInput","props":{"label":{"value":"Login"}},"schema":{"validations":[{"key":"min","args":{"limit":3}},{"key":"includes","args":{"value":"2","message":"Should include 2"}}]},"htmlAttributes":[{"name":"data-testid","value":"login"}]},{"key":"password","type":"RsInput","props":{"label":{"value":"Password"},"type":{"value":"password"}},"schema":{"validations":[{"key":"max","args":{"limit":12}}]},"htmlAttributes":[{"name":"data-testid","value":"password"}]}]},"localization":{},"languages":[{"code":"en","dialect":"US","name":"English","description":"American English","bidi":"ltr"}],"defaultLanguage":"en-US"}

Expected pretty result (shape to match):

{
  "version": "1",
  "form": {
    "key": "Screen",
    "type": "Screen",
    "props": {},
    "children": [
      {
        "key": "login",
        "type": "RsInput",
        "props": {
          "label": {
            "value": "Login"
          }
        },
        "schema": {
          "validations": [
            {
              "key": "min",
              "args": {
                "limit": 3
              }
            },
            {
              "key": "includes",
              "args": {
                "value": "2",
                "message": "Should include 2"
              }
            }
          ]
        },
        "htmlAttributes": [
          {
            "name": "data-testid",
            "value": "login"
          }
        ]
      },
      {
        "key": "password",
        "type": "RsInput",
        "props": {
          "label": {
            "value": "Password"
          },
          "type": {
            "value": "password"
          }
        },
        "schema": {
          "validations": [
            {
              "key": "max",
              "args": {
                "limit": 12
              }
            }
          ]
        },
        "htmlAttributes": [
          {
            "name": "data-testid",
            "value": "password"
          }
        ]
      }
    ]
  },
  "localization": {},
  "languages": [
    {
      "code": "en",
      "dialect": "US",
      "name": "English",
      "description": "American English",
      "bidi": "ltr"
    }
  ],
  "defaultLanguage": "en-US"
}

Fixture source: tests/component/tests/forms/login-form.json.

2. Edit JSON — open existing form

  1. Load tests/component/tests/forms/designer-form.json (or any saved form).
  2. Open Edit JSON.
  3. Confirm the buffer is already pretty-printed and formatOnPaste / formatOnType stay active while editing.

3. Property JSON editor

  1. Open a component with an object/JSON property (e.g. modules / object editor that opens the bottom JSON panel).
  2. Paste a compact object such as {"toolbar":["bold","italic"]}.
  3. Confirm it expands to indented JSON.
  4. Open a calculable/JS editor without autoformat and confirm messy JS is not reformatted on open.

4. Regression

  1. Save after autoformat; reload the form; structure and values match the pasted definition.
  2. Invalid JSON paste should not crash the designer (format may no-op).

@cherepanov cherepanov added this to the 12.2.0 milestone Nov 25, 2026
@cherepanov cherepanov changed the title #12 Add optional Monaco code editor autoformat Add optional Monaco code editor autoformat Nov 25, 2026
@cherepanov
cherepanov marked this pull request as ready for review November 26, 2026 12:24
@cherepanov
cherepanov requested a review from ashalugin November 26, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add optional Monaco code editor autoformat

1 participant